//
//  WKFriendInforListVC.m
//  WKMaybell
//
//  Created by 何文虎 on 2018/12/20.
//  Copyright © 2018 何文虎. All rights reserved.
//

#import "WKFriendInforListVC.h"
#import "WKPlanBookCollectCell.h"
#import "WKFriendInforHeadView.h"



@interface WKFriendInforListVC ()<UITableViewDelegate,UITableViewDataSource>
{
    WKFriendInforHeadView *_headerView;
    CGFloat _headeViewHeight;
    
    SSNavigationBar *_naviBar;
}

@property(nonatomic,strong)UITableView *tableview;
@property(nonatomic,strong)NSMutableArray *dataSource;
@end

@implementation WKFriendInforListVC

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViews];
    [self updata];
}

- (void)initViews{
    
    
    self.tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [self.view addSubview:self.tableview];
    self.tableview.backgroundColor = [UIColor whiteColor];
    self.tableview.tableFooterView = [UIView new];
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, TabBarHeight)];
    [self.tableview registerClass:[WKPlanBookCollectCell class] forCellReuseIdentifier:NSStringFromClass([WKPlanBookCollectCell class])];
    
    _headeViewHeight = (NavBarHeight+130);
    _headerView = [[WKFriendInforHeadView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, _headeViewHeight)];
    _tableview.tableHeaderView = _headerView;
    
    
//    [self.tableview addSubview:_headerView];
//    _tableview.contentInset = UIEdgeInsetsMake(_headeViewHeight, 0, 0, 0);
    
    if (@available(iOS 11.0, *)) {
        _tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    [self initMynavigationBar];
    
}

- (void)initMynavigationBar{
    _naviBar = [[SSNavigationBar alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, NavBarHeight)];
    _naviBar.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_naviBar];
    [_naviBar configMynavibarStyle:SSNavigationBarWhiteStyle];
    [_naviBar hiddenNaviBarLine];
    [_naviBar showShareBarItem];
    @weakify(self);
    _naviBar.backBlock = ^{
        @strongify(self);
        [self backController];
    };
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  self.dataSource.count;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    WKPlanBookCollectCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([WKPlanBookCollectCell class]) forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = self.dataSource[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CGFloat height = 0;
    WKContentListModel *model = [self.dataSource objectAtIndex:indexPath.row];
    height = [WKPlanBookCollectCell hyb_heightForTableView:tableView config:^(UITableViewCell *sourceCell) {
        WKPlanBookCollectCell *cell = (WKPlanBookCollectCell*) sourceCell;
        cell.model = model;
        
    } cache:^NSDictionary *{
        return @{kHYBCacheUniqueKey: model.contentId,
                 kHYBCacheStateKey : @"",
                 // 如果设置为YES，若有缓存，则更新缓存，否则直接计算并缓存
                 // 主要是对社交这种有动态评论等不同状态，高度也会不同的情况的处理
                 kHYBRecalculateForStateKey : @(YES) // 标识不用重新更新
                 };
    }];
    
    
    return height;
}

- (void)updata{
    NSDictionary *dic = @{@"type":@"0",@"headerImagUrl":@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1544598563&di=2411d1f0f5d99380c76dc0d3c04bb138&imgtype=jpg&er=1&src=http%3A%2F%2Ftvax2.sinaimg.cn%2Fcrop.0.0.667.667.1024%2F0077xMUHly8fru1jjd5rnj30ij0ijab3.jpg",@"name":@"会飞的鱼儿",@"membe":@"精英会员",@"content":@"《夜曲》的MV主线是周杰伦扮演的男子思念死去女友的故事，MV的故事也是周杰伦自己构思的，MV中将为失去的女主角弹奏她生前最爱的肖邦的《夜曲》。MV的导演是邝盛，他对周杰伦在MV中的表演表示肯定。而周杰伦本人则表示：“这首歌用死亡来表现歌曲的张力。”《夜曲》的棚内部分是在台湾完成的，为了保持一致拍摄时将当时的服装全部找出来让周杰伦穿上，还在拍摄现场搭起了类似纽约民居的场景，拍摄时回忆及一年前的情景，不禁开玩笑感叹自己走进了时光隧道。",@"images":@[@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1544002093712&di=97ffda895319de384ac0643e43eb79e7&imgtype=0&src=http%3A%2F%2Fcdn.pingwest.com%2Fwp-content%2Fuploads%2F2016%2F05%2Fzhoujielun.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1544002115813&di=c7f9d0be4008644b5e93294d16db97b4&imgtype=0&src=http%3A%2F%2Fdingyue.nosdn.127.net%2F5wGbhURl1KfsTvPS8FqZgqffrVq2DWFCFqtubkZymjDzf1542294767536.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1544002115811&di=795e9941ac71a0a94f7b242b4fb6801b&imgtype=0&src=http%3A%2F%2Fs9.rr.itc.cn%2Fr%2FwapChange%2F20165_25_10%2Fa3fq7o76823521039596.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1544002175623&di=ffd387d0061a82089e0dc200729e47f5&imgtype=0&src=http%3A%2F%2Fi0.hdslb.com%2Fbfs%2Farchive%2F102db6e8ad0be68b5f10d034e58b04cb6f2f94a8.jpg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1544006938715&di=d52a35e0f3bfbd096a81e707e90aff1c&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201508%2F11%2F20150811175706_mrEyn.jpeg",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1544006938589&di=7c44b5c5b142a4e6b4f5bc686757510e&imgtype=0&src=http%3A%2F%2Fgss0.baidu.com%2F-4o3dSag_xI4khGko9WTAnF6hhy%2Fzhidao%2Fpic%2Fitem%2F6a600c338744ebf806d67ca9dbf9d72a6159a784.jpg"],@"video":@"https://xingchenxueyuan.oss-cn-beijing.aliyuncs.com/20180521/%E5%B0%8F%E6%B0%94%E6%B3%A1%E6%88%90%E7%89%87%E6%AD%A3%E5%B8%B8%E8%82%8C%E8%82%A4%E6%B5%81%E7%A8%8B.mp4",@"comment":@"流行结合古典的夜曲，哥的最爱，哥真正入坑专！吸粉最多的一张专辑，范特西卖的那么好，十一月的肖邦居功至伟！因为周当时的女朋友爱听慢情歌，所以这张专辑比前5张专辑多",@"questionStr":@"全球最大的周杰伦网站!是一家以提供周杰伦相关信息为主的专业网站,成立于2001年11月9日。主要包括周杰伦新闻、资料、图片"};
    
    self.dataSource = nil;
    if (self.dataSource == nil) {
        self.dataSource = [NSMutableArray arrayWithCapacity:0];
    }
    for (int i =0; i<20; i++) {
        WKContentListModel *model = [WKContentListModel mj_objectWithKeyValues:dic];
        model.contentId = IntToString(i);
        int selectIndex = (int)(1 + (arc4random() % (6 -1 + 1)));
        NSMutableArray *randomArr = [NSMutableArray arrayWithCapacity:0];
        for (int i = 0; i<selectIndex; i++) {
            [randomArr addObject:[NSString stringWithFormat:@"%@", model.images[i]]];
        }
        model.images = [NSArray arrayWithArray:randomArr];
        if (selectIndex%2==0) {
            model.comment = @"";
            
            
        }
        
        
        
        [self.dataSource addObject:model];
    }
    
    [self.tableview reloadData];
    
    
}


-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
//    if (scrollView.contentOffset.y >_headeViewHeight) {
//        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
//        _naviBar.backgroundColor = [UIColor whiteColor];
//        [_naviBar showNaviBarLine];
//        [_naviBar configMynavibarStyle:SSNavigationBarBlackStyle];
//        _naviBar.titleLable.text = @"一直爱睡觉的猫咪";
//    }else{
//        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
//        _naviBar.backgroundColor = [UIColor clearColor];
//        [_naviBar hiddenNaviBarLine];
//        [_naviBar configMynavibarStyle:SSNavigationBarWhiteStyle];
//        _naviBar.titleLable.text = @"";
//    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
